<template>
<div><br>
  <el-form v-model="surgeryForm" label-width="80px">
        <el-form-item label="病人名字">
                <el-input :value="patient.name"></el-input>
            </el-form-item>
            <el-form-item label="主治医生">
                <el-input :value="doctor.docName"></el-input>
            </el-form-item>
        <el-form-item label="手术项目">
            <el-select v-model="surgeryForm.sdSiId" clearable="">
                <el-option
                v-for="item in options"
                :key="item.id"
                :label="`${item.siName}`"
                :value="item.id"
                />
            </el-select>
        </el-form-item>
        <el-form-item label="手术时间">
            <el-date-picker v-model="surgeryForm.sdDate" value-format="yyyy-MM-dd HH:mm:ss" type="datetime"
                default-time="12:00:00"
                placeholder="请选择手术时间">
            </el-date-picker>
        </el-form-item>
        <el-form-item>
            <el-button type="warning" size="mini" @click="dialogVisible=false">重置</el-button>
            <el-button type="primary" size="mini" @click="addSMItem">确定</el-button>
        </el-form-item>
    </el-form>
    <span style="color: red;">{{ msg }}</span>
    </div>
</template>

<script>
export default {
    props: {
         caseId:{
             type: Number,
             required: true
         }
     },
    data(){
        return{
            surgeryForm:{
                sdCaseId:"",
                sdWorkerId:"",
                sdSiId:"",
                sdDate:""
            },//手术申请
            patient:{},
            doctor:{},
            options:{},
            msg:''
        }
    },
    methods:{
        //查找医生信息
        queryDoctor(){
         this.$axios.get("api/doctor/queryDoctor")
         .then(res=>{
             if(res.data.code==200){
                 this.doctor=res.data.data;
                 this.querySurgeryManage()
             }
         })
         },
         //查找病人信息
         queryPatient(){
             this.$axios.get("api/doctor/queryPatient/"+this.caseId)
             .then(res=>{
             if(res.data.code==200){
                 this.patient=res.data.data;
                 console.log(this.patient)
             }
         }) 
         },
         //查找手术项目
         querySurgeryManage(){
            let tde ={};
            tde.id=this.doctor.docDeId
            this.$axios.post("api/surgery/queryByDeList",tde)
             .then(res=>{
             if(res.data.code==200){
                 this.options=res.data.data;
                 console.log(this.options)
             }
         }) 
         },
         //添加手术申请
         addSMItem(){
            console.log("sdDate")
            console.log(this.surgeryForm.sdDate)
            if(this.surgeryForm.sdDate==null || this.surgeryForm.sdDate==''){
                this.msg="请选择预约手术时间"
                return;
            }
            if(this.surgeryForm.sdSiId==null || this.surgeryForm.sdSiId==''){
                this.msg="请选择预约手术项目"
                return;
            }
            this.surgeryForm.sdCaseId=this.patient.id
            this.surgeryForm.sdWorkerId=this.doctor.id
            this.$axios.post("api/patientsurgery/addSMItem",this.surgeryForm)
             .then(res=>{
                console.log("进入添加")
             if(res.data.code==200){
                 this.$message.success("您已提交手术申请，请等待手术室安排")
                 this.closeDialogWithData()
             }
         }) 
         },
         closeDialogWithData() {
             // 触发事件并传递数据给父组件
             this.$emit('closeDialog', this.patient.id); // 替换 dataToPass 为你想要传递的数据
         },
    },
    created(){},
    mounted(){
        this.queryDoctor()
        this.queryPatient()
    }
}
</script>

<style>

</style>